<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>沃币充值</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
</head>
<body>

<div class="layui-fluid">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;margin-left: -40px">输入充值金额:</label><br /><br /><br />
            <div class="layui-input-block">
                <input style="width: 270px;margin-left: -35px" type="text" name="depid" id="depid" placeholder="请输入充值金额" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div style="margin-left: 100px">
            <button id="qr" style="margin-left: 85px;" type="button" class="layui-btn" lay-filter="formDemo">确认</button>
            <!--<button id="fanhui" type="button" class="layui-btn" lay-filter="formDemo">返回</button>-->
        </div>
    </form>
</div>
</body>
</html>
<script>
    layui.use('table', function () {
        var $ = layui.$
        var table = layui.table
        var data = layui.data("stationdata");
        console.log(data)

        //返回的监听事件
        $("#fanhui").click(function () {
            location = "stationMoney.html";
        })
        $("#qr").click(function () {

            var depid=$("#depid").val();

            var depid2= /^([1-9][0-9]*){1,3}$/;
            if(!depid2.test(depid)){
                layer.msg("格式错误",{icon:2})
                return;
            }
            // 格式正m 确充值
            $.ajax({
                url: '/admin/station-recharge/insertRecharge',
                type: "post",
                data:{
                    stationRechargeSum:depid,
                    stationRechargeAdmin:data.getdata.station_admin_id,
                    stationRechargeStationId:data.getdata.station_id
                },
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg("充值成功", {
                            icon: 1,
                            time:500
                        });

                        setTimeout(function (){
                            // 格式正m 确充值
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);    //关闭弹出层
                            window.parent.location.reload();   //刷新父界面
                        },500);
                        return;
                    }
                    layer.msg("余额不足", {
                        icon: 2
                    })
                    return;
                },
                error:function(res){//服务器异常
                    layer.msg("失败,服务器异常",{icon:2});
                }
            })
            //   }
            // })

        })
    })
</script>